function _toConsumableArray(arr) {
  return (
    _arrayWithoutHoles(arr) ||
    _iterableToArray(arr) ||
    _unsupportedIterableToArray(arr) ||
    _nonIterableSpread()
  );
}
function _nonIterableSpread() {
  throw new TypeError(
    'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
  );
}
function _iterableToArray(iter) {
  if (
    (typeof Symbol !== 'undefined' && iter[Symbol.iterator] != null) ||
    iter['@@iterator'] != null
  )
    return Array.from(iter);
}
function _arrayWithoutHoles(arr) {
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _slicedToArray(arr, i) {
  return (
    _arrayWithHoles(arr) ||
    _iterableToArrayLimit(arr, i) ||
    _unsupportedIterableToArray(arr, i) ||
    _nonIterableRest()
  );
}
function _nonIterableRest() {
  throw new TypeError(
    'Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
  );
}
function _unsupportedIterableToArray(o, minLen) {
  if (!o) return;
  if (typeof o === 'string') return _arrayLikeToArray(o, minLen);
  var n = Object.prototype.toString.call(o).slice(8, -1);
  if (n === 'Object' && o.constructor) n = o.constructor.name;
  if (n === 'Map' || n === 'Set') return Array.from(o);
  if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
    return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
  if (len == null || len > arr.length) len = arr.length;
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  return arr2;
}
function _iterableToArrayLimit(arr, i) {
  var _i =
    null == arr
      ? null
      : ('undefined' != typeof Symbol && arr[Symbol.iterator]) || arr['@@iterator'];
  if (null != _i) {
    var _s,
      _e,
      _x,
      _r,
      _arr = [],
      _n = !0,
      _d = !1;
    try {
      if (((_x = (_i = _i.call(arr)).next), 0 === i)) {
        if (Object(_i) !== _i) return;
        _n = !1;
      } else
        for (
          ;
          !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i);
          _n = !0
        );
    } catch (err) {
      (_d = !0), (_e = err);
    } finally {
      try {
        if (!_n && null != _i.return && ((_r = _i.return()), Object(_r) !== _r)) return;
      } finally {
        if (_d) throw _e;
      }
    }
    return _arr;
  }
}
function _arrayWithHoles(arr) {
  if (Array.isArray(arr)) return arr;
}
import EyeInvisibleOutlined from '@ant-design/icons/EyeInvisibleOutlined';
import EyeOutlined from '@ant-design/icons/EyeOutlined';
import ReloadOutlined from '@ant-design/icons/ReloadOutlined';
import { useFetch } from '@szzj/hooks';
import { Button, Form, Input } from 'antd';
import 'antd/es/button/style/index.js';
import 'antd/es/form/style/index.js';
import 'antd/es/input/style/index.js';
import classnames from 'classnames';
import React, { Fragment } from 'react';
import './index.less';
var FormItem = Form.Item;
/**
 * 登录表单
 * @param param0
 * @returns
 */
export default function LoginForm(_ref) {
  var _ref$size = _ref.size,
    size = _ref$size === void 0 ? 'large' : _ref$size,
    _ref$passwordRules = _ref.passwordRules,
    passwordRules = _ref$passwordRules === void 0 ? [] : _ref$passwordRules,
    getCaptureUrl = _ref.getCaptureUrl,
    onLogin = _ref.onLogin;
  var _useFetch = useFetch(
      getCaptureUrl !== null && getCaptureUrl !== void 0
        ? getCaptureUrl
        : function () {
            return Promise.resolve(undefined);
          },
    ),
    fetchCaptureUrl = _useFetch.fetch,
    captureUrl = _useFetch.data;
  var _Form$useForm = Form.useForm(),
    _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
    form = _Form$useForm2[0];
  var handleSubmit = function handleSubmit() {
    form
      .validateFields()
      .then(function (fields) {
        onLogin(fields).then(function (res) {
          if (!(res !== null && res !== void 0 && res.success)) {
            fetchCaptureUrl();
          }
        });
      })
      .catch(function (err) {
        return console.warn(err);
      });
  };
  return /*#__PURE__*/ React.createElement(
    'div',
    {
      className: classnames('szzj-login-form', size),
    },
    /*#__PURE__*/ React.createElement(
      Form,
      {
        form: form,
        validateTrigger: 'onBlur',
        scrollToFirstError: true,
        onKeyUp: function onKeyUp(event) {
          if (event.key === 'enter') handleSubmit();
        },
        onFinish: handleSubmit,
      },
      /*#__PURE__*/ React.createElement(
        FormItem,
        {
          name: 'account',
          rules: [
            {
              required: true,
              whitespace: true,
              message: '请输入用户名',
            },
          ],
        },
        /*#__PURE__*/ React.createElement(Input, {
          placeholder: '\u8BF7\u8F93\u5165\u7528\u6237\u540D',
          size: size,
          maxLength: 50,
        }),
      ),
      /*#__PURE__*/ React.createElement(
        FormItem,
        {
          name: 'password',
          rules: [
            {
              required: true,
              whitespace: true,
              message: '请输入密码',
            },
          ].concat(_toConsumableArray(passwordRules)),
        },
        /*#__PURE__*/ React.createElement(Input.Password, {
          placeholder: '\u8BF7\u8F93\u5165\u5BC6\u7801',
          size: size,
          maxLength: 30,
          iconRender: function iconRender(visible) {
            return visible
              ? /*#__PURE__*/ React.createElement(EyeOutlined, null)
              : /*#__PURE__*/ React.createElement(EyeInvisibleOutlined, null);
          },
        }),
      ),
      getCaptureUrl &&
        /*#__PURE__*/ React.createElement(
          Fragment,
          null,
          /*#__PURE__*/ React.createElement(
            FormItem,
            {
              name: 'imageCode',
              rules: [
                {
                  required: true,
                  whitespace: true,
                  message: '请输入验证码',
                },
              ],
            },
            /*#__PURE__*/ React.createElement(Input, {
              size: size,
              placeholder: '\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801',
              maxLength: 4,
            }),
          ),
          /*#__PURE__*/ React.createElement(
            'div',
            {
              className: 'szzj-login-form-capture-wrapper',
            },
            /*#__PURE__*/ React.createElement('img', {
              alt: '\u56FE\u7247\u9A8C\u8BC1\u7801',
              src: captureUrl,
              className: 'szzj-login-form-capture',
            }),
            /*#__PURE__*/ React.createElement(
              'a',
              {
                className: 'szzj-login-form-capture-tips',
                onClick: fetchCaptureUrl,
              },
              /*#__PURE__*/ React.createElement(ReloadOutlined, {
                className: 'szzj-login-form-capture-icon',
              }),
              '\u6362\u4E00\u5F20',
            ),
          ),
        ),
      /*#__PURE__*/ React.createElement(
        Button,
        {
          htmlType: 'submit',
          type: 'primary',
          size: size,
          className: 'szzj-login-form-button',
        },
        '\u767B\u5F55',
      ),
    ),
  );
}
